package models

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

var ormer orm.Ormer

//用户信息表
type Xxp_kol struct {
	Id             int64
	Mobile         string //手机号码
	Name           string //姓名
	Openid         string //微信openid
	Id_card        string //身份证照片
	Nickname       string //昵称
	Pid            int    //上级用户id
	Head_img       string //图像
	InvitationCode string //邀请码
	Status         int    //状态0:禁用,1:正常
	Created        int64
	Modified       int64
}

type Xxp_kol_assets struct {
	Id       int64   //id
	Uid      int64   //kolid
	Balance  float64 //余额
	Frozen   float64 //冻结金额
	Bond     float64 //保证金
	Quota    float64
	Modified int64
}

type Xxp_kol_assets_log struct {
	Id       int64   //id
	Uid      int64   //kolid
	Types    int     //类型
	Money    float64 //冻结金额
	Transfer int     //1转入，2转出
	Status   int     //状态
	Created  int64
}

//短信验证码表
type Xxp_smscode struct {
	Id       int64
	Uid      int64
	Mobile   string
	Code     string
	Codetime int64
}

//商品表
type Xxp_goods struct {
	Id               int
	Title            string
	Description      string
	Thumb            string
	Types            int
	Carousel_imgs    string
	Detail_imgs      string
	Stocks           int
	Remaining_stocks int
	Sales            int
	Rating           float64
	Base_price       float64
	Price            float64
	Commission       float64
	End_time         int
	Purchase_limit   int
	Status           int
	Share            string
	Address          string
	Created          int
	Modified         int
}

//课程表
type Xxp_schedule struct {
	Id     int
	Gid    int
	Name   string
	Remark string
	Sort   int
	Times  int
}

func init() {
	dbhost := beego.AppConfig.String("db.host")
	dbport := beego.AppConfig.String("db.port")
	dbuser := beego.AppConfig.String("db.user")
	dbpass := beego.AppConfig.String("db.pass")
	dbname := beego.AppConfig.String("db.name")

	dsn := dbuser + ":" + dbpass + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?charset=utf8mb4"
	//beego.Debug(dsn)
	orm.RegisterDriver("mysql", orm.DRMySQL)
	//注册表
	orm.RegisterModel(new(Xxp_kol), new(Xxp_kol_assets), new(Xxp_shop), new(Xxp_kol_assets_log), new(Xxp_goods), new(Xxp_schedule))
	orm.RegisterDataBase("default", "mysql", dsn)

	//var w io.Writer
	if beego.BConfig.RunMode == "dev" {
		orm.Debug = true
	}

	//orm.DebugLog = orm.NewLog(w)

	//初始化orm
	ormer = orm.NewOrm()
	ormer.Using("default") // 默认使用 default，你可以指定为其他数据库

}
